import time

import numpy as np
import pyvisa as visa
from Instruments import GHS_64,InstrumentInitial,Keysight34461A
import serial



if __name__ == '__main__':
    rm = visa.ResourceManager()

    print(rm.list_resources())
    # session = serial.Serial('COM9', 9600, timeout=1)
    #
    # print(session.read('IDN*'))
    #======================one===========================

    a = rm.open_resource('169.254.4.61')
    print(f'设备基本信息：{("*IDN?")}')
    print(f'当前电压值：：{a.query("MEAS:VOLT:DC?")}')
    print(f'当前电流值：{a.query("MEAS:CURR:DC?")}')

    # ======================two===========================
    # a = rm.open_resource('TCPIP::169.254.4.61::INSTR')
    # print(f'设备基本信息：{a.query("*IDN?")}')
    # print(f'当前电压值：：{a.query("MEAS:VOLT:DC?")}')
    # print(f'当前电流值：{a.query("MEAS:CURR:DC?")}')

    # print(f'初始化：{a.query("*RST")}')

    # ======================three===========================

    dmm = Keysight34461A(rm.open_resource('TCPIP::169.254.103.58::INSTR'))
    counts=1
    plc=0.02
    voltages=dmm.dc_voltage(counts,plc)
    print(voltages)
    # ----------------------------
    counts = 10
    plc = 0.02
    average_voltage = dmm.dc_voltage_counts(counts, plc)
    # ----------------------------
    wait_time = 2
    current = dmm.measure_dc_current(wait_time)